def jostphus(n,m):
    people = list(range(n))
    m -= 1
    k = m % n
    while(len(people)>1):
        del people[k]
        k = (k+m) % len(people)
    return  people[0]
if __name__ == '__main__':
    print(jostphus(13,3))